package com.yh.consumer;

import com.rabbitmq.client.Channel;
import com.yh.service.PayService;
import com.yh.utils.Constants;
import com.yh.vo.OrderVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.log4j.Logger;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

/**
 * @author yuhuan
 * @date 2022/01/13
 */
@Service
@RabbitListener(queues = Constants.RabbitMqData.PAY_QUEUE_NAME, ackMode = "MANUAL")
public class PayModuleConsumerBase extends BaseMqConsumer {
    /**
     * 日志
     */
    private static final Logger logger = Logger.getLogger(PayModuleConsumerBase.class);

    @DubboReference(check = false)
    private PayService payService;

    @RabbitHandler
    public void receiveVirtualRefundMessage(OrderVO orderVO, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
        logger.debug(">>>>> 收到退款申请，订单号：" + orderVO.getOrderinfo().getOrderId());
        payService.receiveRefund(orderVO);
        // 消息确认
        messageConfirmation(channel, deliveryTag);
    }
}
